//logs.js
const util = require('../../utils/util.js')

Page({
  data: {
    phone:'',
    gonghao:'',
    yanzhengma:''
  },
  onLoad: function () {
    wx.setNavigationBarTitle({
      title: '绑定'
    })
  },
  getcode(){
    if (!this.data.phone) {
      wx.showToast({
        title: '请输入手机号',
        icon: 'none'
      })
      return;
    }
    wx.showLoading()
    var that = this
    wx.request({
      url: 'https://www.easy-mock.com/mock/5a797f07603b08213e149ab4/example/getcode',
      method: 'get',
      data: {
        phone: that.data.phone
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        if (res.data.errcode === 0) {
          wx.hideLoading()
          wx.showToast({
            title: res.data.errmsg
          })
        } else {
          wx.hideLoading()
          wx.showToast({
            title: res.data.errmsg
          })
        }
      }
    })
  },
  bindPhoneInput(e){
    this.setData({
      phone: e.detail.value
    })
  },
  bindGongHaoInput(e){
    this.setData({
      gonghao: e.detail.value
    })
  },
  submit(){
    var that=this
    if(!this.data.phone){
      wx.showToast({
        title: '请输入手机号',
        icon: 'none'
      })
      return;
    }
    if (!this.data.gonghao) {
      wx.showToast({
        title: '请输入工号',
        icon:'none'
      })
      return;
    }
    if (!this.data.yanzhengma) {
      wx.showToast({
        title: '请输入验证码',
        icon: 'none'
      })
      return;
    }
    wx.showLoading()
    wx.request({
      url: 'http://www.easy-mock.com/mock/5a797f07603b08213e149ab4/example/login',
      method: 'get',
      data:{
        phone: that.phone,
        gonghao: that.gonghao,
        yanzhengma: that.yanzhengma
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        if(res.data.errcode===0){
          wx.hideLoading()
          wx.showToast({
            title: res.data.errmsg
          })
        }else{
          wx.hideLoading()
          wx.showToast({
            title: res.data.errmsg
          })
        }
      }
    })
  },
  bindYanZhengInput(e){
    this.setData({
      yanzhengma: e.detail.value
    })
  }
})
